package com.ofa.action;

import java.io.Serializable;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.ofa.base.BaseAction;
import com.ofa.base.Pagination;
import com.ofa.entity.Person;
import com.ofa.enums.GenderEnum;
import com.ofa.service.PersonService;
import com.ofa.util.CommonUtils;

public class PersonAction extends BaseAction {
	
	private int maxResults = 10;
	private int firstResult = 0;
	
	private Integer id;
	private List<Serializable> ids;
	private Integer orgId;

	private PersonService personService;
	
	private Person person;
	
	private List<Person> personList;
	
	private Pagination<Person> pagination;
	
	private GenderEnum[] genderEnum;

	
	
	@Override
	public String execute(){
		String offset = ServletActionContext.getRequest().getParameter("pager.offset");
		if(CommonUtils.isNotEmpty(offset))
			firstResult = Integer.valueOf(offset);
		
		pagination = personService.queryPersons(person, firstResult, maxResults);
		return SUCCESS;
	}

	public String preSave(){
		genderEnum = GenderEnum.values();
		return "preSave";
	}
	
	public String save(){
		personService.save(person, orgId);
		return "save";
	}

	public String preUpdate(){
		person = personService.get(id);
		//personList = personService.queryPersons(person, 0);
		return "toUpdate";
	}
	
	public String update(){
		personService.update(person);
		return "update";
	}
	
	public String delete(){		
		personService.delete(id);
		return "delete";
	}
	
	public String get(){
		person = personService.get(id);
		
		return "get";
	}

	
	
	public PersonService getPersonService() {
		return personService;
	}
	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}

	public Person getPerson() {
		return person;
	}
	public void setPerson(Person person) {
		this.person = person;
	}


	public List<Person> getPersonList() {
		return personList;
	}
	public void setPersonList(List<Person> personList) {
		this.personList = personList;
	}

	public Pagination<Person> getPagination() {
		return pagination;
	}
	public void setPagination(Pagination<Person> pagination) {
		this.pagination = pagination;
	}

	public int getMaxResults() {
		return maxResults;
	}
	public void setMaxResults(int maxResults) {
		this.maxResults = maxResults;
	}

	public int getFirstResult() {
		return firstResult;
	}
	public void setFirstResult(int firstResult) {
		this.firstResult = firstResult;
	}

	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}

	public List<Serializable> getIds() {
		return ids;
	}
	public void setIds(List<Serializable> ids) {
		this.ids = ids;
	}

	public Integer getOrgId() {
		return orgId;
	}
	public void setOrgId(Integer orgId) {
		this.orgId = orgId;
	}

	public GenderEnum[] getGenderEnum() {
		return genderEnum;
	}

	public void setGenderEnum(GenderEnum[] genderEnum) {
		this.genderEnum = genderEnum;
	}
	
	

	
}
